#ifndef GANGIAFRAME_H
#define GANGIAFRAME_H

#include "Gangia_GUI.h"

#include <wx/msw/registry.h>
#include "wx/filefn.h"
#include	"wx/socket.h"
//#include	"matlabeng.h"

//Virtual Devices
#include	"devices/Virtual/PlayFile.h"
#include	"devices/Virtual/Simulation.h"
#include	"devices/Virtual/InteractivePlayFile.h"

//Polimi Devices
//#include	"devices/KimeraII_Processing.h"
#include	"devices/Polimi/Bluesilk/BlueSilk.h"
#include	"devices/Polimi/KimeraII/KimeraII.h"
#include	"devices/Polimi/PLE/PLE.h"
#include	"devices/Polimi/PLE/PLE16bit.h"
#include	"devices/Polimi/TermoPle/TermoPLE.h"
#include	"devices/Polimi/ResegUP/ResegUP.h"
#include	"devices/Polimi/ArduinoECG/ArduinoECG.h"

//Other
#include	"devices/Neuroscan/Neuroscan.h"

//Sxt
#include	"devices/SXT/Phedra/Phedra.h"
#include	"devices/SXT/Protheo/ProtheoII.h"

//Comftech
#include	"devices/ComfTech/Daddy.h"

//Emotiv
#include	"devices/Emotiv/Emotiv.h"
#include	"Devices/Emotiv/MyEmotiv.h"

//G.tec
#ifdef HAVE_GTEC_LIBRARY
#include	"devices/Gtec/gMobiLab/gMobilab.h"
#endif
#ifdef HAVE_GTEC_USB_LIBRARY
#include	"devices/Gtec/gUSBAmp/mygUSBAmp.h"
#endif

//BrainProducts
#include	"devices/BrainProducts/BrainProducts.h"
#include	"devices/BrainProducts/VAmp/VAmp.h"


//Braintronics
#include	"devices/Braintronics/EEG1042.h"
//#include	"devices/Braintronics/EEG1142.h"
//#include	"devices/Braintronics/EEG1164.h"
//#include	"devices/Braintronics/EEG1166.h"

#include	"devices/ST/AP.h"

//For Impedance check
#include	"ImpCheck.h"
#include	"devices/Gtec/gUSBAmp/gUSBImp.h"
#include	"devices/BrainProducts/VAmp/VAmpImp.h"

#include	"htmlhelp.h"
#include	"wx/html/helpctrl.h"
#include	<wx/msw/helpchm.h>



/*
#include "c4m_ssvep.h"
#include "MAT_MIRTF.h"
#include "Remote_ssvep.h"
#include "matssvep.h"
#include "algosimulator.h"
*/
/*
#define		OFF_X		5
#define		OFF_Y		3

#define		MEAN_X		46
#define		MEAN_Y		49

#define		LIMBO_X		2
#define		LIMBO_Y		3*/

// SOCKET PORT
#define		WX_THE_PORT	3001

const int MAX_ALGORITHMS = 10;
typedef struct AlgorithmDescriptor
{
	wxString Name, DLL;
}AlgorithmDescriptor;

class GangiaFrame : public MainFrame
{
public:
	GangiaFrame( wxWindow *parent = NULL, int id = -1 );
	~GangiaFrame();
	void StopAcquisition(void);
private:
	
	CDatSaver			*pNavigatorData;
	Instrument			*pNavigator;
	wxSocketServer		*m_server;
	wxSocketBase		*sock;
	MainPanel			*panel;

	//double				IncomingFlags;
	wxString			NavFileName,FilePath;	
	long				SavedFiles;
	wxTimer				Timer,TimerHide;
	int					contRow,contRow2;
	wxString			tFileName;
	//double Meanx;
	//double Meany;
	void Prompt(wxString *Text){panel->m_TextOut->AppendText(*Text);}
	void Prompt(wxString Text){panel->m_TextOut->AppendText(Text);}
	//void StartSaving(void);
	void OnShowFeedback(wxCommandEvent& event)
	{
		if(pAlgorithm != NULL)pAlgorithm->ToggleShow();
	}
	
	void OnShowPlot(wxCommandEvent& event)
	{
		if(pNavigator != NULL) 
		{
			pNavigator->ToggleShow();
			if(pNavigator->pPlotFrame->IsShown())
				this->showplot->Check(true);
			else
				this->showplot->Check(false);
		}

	}
	void OnStartAcquisition(wxCommandEvent& event)
	{
		event.Skip();
		
		if (pAlgorithm!=NULL)
			pAlgorithm->RunBeforeStart();

		StartAcquisition();
	}
	void StartAcquisition(void);

	
	void OnStopAcquisition(wxCommandEvent& event)
	{
		event.Skip();
		StopAcquisition();
	}

	void OnStartRemote(wxCommandEvent& event)
	{
		event.Skip();
		OpenConnection();
	}
	
	
	void OnStartMatlab(wxCommandEvent& event);
	void OnCloseMatlab(wxCommandEvent& event);

	void GetFileName(void);
	void SaveAs(wxCommandEvent& event)
	{
		event.Skip();
		GetFileName();
	}
	void OnResize(wxSizeEvent& event);
	void LoadAlgoSettings(void);
	void InitAlgorithm(int Kind);
	void CloseConnection(void);
	void CloseBTConnection(wxCommandEvent& event);
	bool OpenConnection(void);
	void OnServerEvent(wxSocketEvent& event);
	void OnSocketEvent(wxSocketEvent& event);
	void OnExit( wxCommandEvent& event );
	void OnAbout( wxCommandEvent& event );
	void RefreshUI(wxTimerEvent& Event);
	void RefreshLine(wxTimerEvent& Event);
	void LoadRegistry(void);
	void SaveRegistry(void);
	void OnClose(wxCloseEvent &Event);
	void ContorlAlgorihms(wxCommandEvent& event);
	int isCalibrating;
	bool CustomFileSelected;
	void ControlDevice(wxCommandEvent& event);
	void CheckImpedance(wxCommandEvent& event);

	void OpenHelpHim(wxCommandEvent& event); 
	void OpenHelpBCI(wxCommandEvent& event); 
	void OpenAbout(wxCommandEvent& event);
	void OpenFile(wxCommandEvent& event);
	
	void OnToggleControls (wxCommandEvent& event);
	void OnToggleStatus (wxCommandEvent& event);
	void OnToggleLog (wxCommandEvent& event);

	void OnMenu(wxCommandEvent &event);
	void OnHideAll(wxCommandEvent &event);

	void OnAEnima(wxCommandEvent& event);

	void Configure(wxCommandEvent& event);
	DECLARE_EVENT_TABLE();

	Algorithm *pAlgorithm;
	HINSTANCE	hLib;
	AlgorithmDescriptor	AlgoDescr[MAX_ALGORITHMS];
	ImpCheck *ImpDia;
	ImpCheck2 *ImpDia2;
	wxBoxSizer* sizer;
	int prevSel;

};
#endif // GANGIAFRAME_H
